/**
 * Copyright (c) 2009-2012 XTEAM
 * All rights reserved.
 */
/**
 * File：SyncObject.java
 * History:
 *         2012-6-14: Initially created, Chrise.
 */
package com.xteam.ecsystem.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 同步对象。
 * @author Chrise
 */
public class SyncObject implements Serializable {
	
	private static final long serialVersionUID = 2709387244558787692L;
	
	private boolean remote;
	private List<WebService> service;
	
	/**
	 * 同步对象构造方法。
	 */
	public SyncObject() {
		this(false, new ArrayList<WebService>());
	}
	
	/**
	 * 同步对象构造方法。
	 * @param remote
	 * @param service
	 */
	public SyncObject(boolean remote, List<WebService> service) {
		this.remote = remote;
		this.service = service;
	}
	
	/**
	 * 是否为远程同步。
	 * @author Chrise 2012-6-14
	 * @return
	 */
	public boolean isRemote() {
		return remote;
	}
	
	/**
	 * 设置是否为远程同步。
	 * @author Chrise 2012-6-14
	 * @param remote
	 */
	public void setRemote(boolean remote) {
		this.remote = remote;
	}
	
	/**
	 * 获取同步服务列表。
	 * @author Chrise 2012-6-14
	 * @return
	 */
	public List<WebService> getService() {
		return service;
	}
	
	/**
	 * 设置同步服务列表。
	 * @author Chrise 2012-6-14
	 * @param service
	 */
	public void setService(List<WebService> service) {
		this.service = service;
	}
	
	/**
	 * 转换成JSON字符串。
	 * @author Chrise 2012-6-14
	 * @return
	 */
	public String toJson() {
		if (service.isEmpty()) {
			return "{remote:'" + remote + "', service:[]}";
		}
		
		String lj = "[" + service.get(0).toJson();
		for (int index = 1; index < service.size(); index ++) {
			lj += ", " + service.get(index).toJson();
		}
		lj += "]";
		
		return "{remote:'" + remote + "', service:" + lj + "}";
	}
	
	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "{remote=" + remote + ", service=" + service + "}";
	}
}
